package com.roocon.design_pattern.chapter03_readwrite_lock;

public class ReaderWorker extends Thread {

  private final ShareData shareData;

  public ReaderWorker(ShareData shareData) {
    this.shareData = shareData;
  }


  @Override public void run() {
    try {
      while (true) {
        char[] ch = shareData.read();
        System.out.println(toString(ch));
      }
    } catch (InterruptedException e) {
      //ignore
    }
  }

  public String toString(char[] chars) {
    return "ReaderWorker{" +
        "thread = " + Thread.currentThread().getName() +
        "\tread = " + String.valueOf(chars) +
        '}';
  }
}
